﻿

using System;
using System.Windows.Forms;
using SDFL.Native;

namespace QuickClipboard
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        protected override void WndProc(ref Message m)
        {
            const int WM_HOTKEY = 0x0312; 
            //按快捷键 
            switch (m.Msg)
            {
                case WM_HOTKEY:
                    switch (m.WParam.ToInt32())
                    {
                        case 101:    //按下的是Ctrl+1
                            //此处填写快捷键响应代码 
                            Clipboard.SetText(textBox1.Text);
                            break;
                        case 102:    //按下的是Ctrl+2
                            //此处填写快捷键响应代码 
                            Clipboard.SetText(textBox2.Text);
                            break;
                        case 103:    //按下的是Ctrl+3
                            //此处填写快捷键响应代码 
                            Clipboard.SetText(textBox3.Text);
                            break;
                        case 104:    //按下的是Ctrl+4
                            //此处填写快捷键响应代码
                            Clipboard.SetText(textBox4.Text);
                            break;
                    }
                    break;
            }

            base.WndProc(ref m);
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            //MessageBox.Show("程序将最小化到系统托盘区");
            e.Cancel = true; // 取消关闭窗体 
            this.Hide();
            //this.ShowInTaskbar = false;//取消窗体在任务栏的显示 
            this.notifyIcon1.Visible = true;//显示托盘图标 
        }

        private void showWindowToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Show();
            this.ShowInTaskbar = true;
            this.notifyIcon1.Visible = false;
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            NativeMethods.UnregisterHotKey(Handle, 101);
            NativeMethods.UnregisterHotKey(Handle, 102);
            NativeMethods.UnregisterHotKey(Handle, 103);
            NativeMethods.UnregisterHotKey(Handle, 104);
            System.Environment.Exit(0);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            NativeMethods.RegisterHotKey(Handle, 101, NativeMethods.KeyModifiers.Ctrl, Keys.D1);
            NativeMethods.RegisterHotKey(Handle, 102, NativeMethods.KeyModifiers.Ctrl, Keys.D2);
            NativeMethods.RegisterHotKey(Handle, 103, NativeMethods.KeyModifiers.Ctrl, Keys.D3);
            NativeMethods.RegisterHotKey(Handle, 104, NativeMethods.KeyModifiers.Ctrl, Keys.D4);
        }
    }
}
